package handlers;

import database.DBException;
import database.IDBContext;
import models.User;
import overclocking.container.IContainer;

import java.util.List;

public class Authentificator implements IAuthentificator {
    private IDBContext sessionsPool;

    public Authentificator(IContainer container) {
        this.sessionsPool = container.get(IDBContext.class);
    }

    @Override
    public User authentificate(String login, int passwordHash) throws DBException {
        List<User> list = sessionsPool.selectUserByLogin(login);
        if (list.size() > 0) {
            User candidate = (User) list.get(0);
            if (candidate.passwordHash == passwordHash)
                return candidate;
        }
        return User.Unknown;
    }
}
